//
// Created by richard on 2018-12-25.
//

#ifndef SEEDCULTURE_SIMLINEARSENSOR_H
#define SEEDCULTURE_SIMLINEARSENSOR_H


#include <thread>

class SimLinearSensor {
private:
    uint16_t value;
    uint16_t step = 0;
    uint16_t threadStep = 0;
    int16_t backgroundStep = -1;
    uint16_t backgroundMax = 1000;
    uint16_t backgroundMin = 0;
    int timeStep = 1;        // unit second
    std::thread * thread;
    bool isRaise = true;
    void initThread();
    static void threadFunc(SimLinearSensor * p);
public:
    SimLinearSensor(uint16_t value, int timeStep);
    explicit SimLinearSensor(uint16_t value);
    void pause();
    void startRaise();
    void startRaise(uint16_t step);
    void raise();
    void raise(uint16_t step);
    void startReduce();
    void startReduce(uint16_t step);
    void reduce();
    void reduce(uint16_t step);
    uint16_t get();
    void setBackgroundStep(int16_t step);
    void setBackgroundMin(uint16_t min);
    void setBackgroundMax(uint16_t max);
    void setBackgroundTarget(uint16_t target);
    void setBackgroundTarget(uint16_t target, uint16_t ratio);

    virtual void loopCallback(){};
};


#endif //SEEDCULTURE_SIMLINEARSENSOR_H
